package com.zzw.oa.service.Impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zzw.model.process.ProcessTemplate;
import com.zzw.oa.mapper.OaProcessTemplateMapper;
import com.zzw.oa.service.OaProcessTemplateService;

import com.zzw.oa.service.OaProcessTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 审批模板 服务实现类
 * </p>
 *
 * @author zzw
 * @since 2023-05-04
 */
@Service
public class OaProcessTemplateServiceImpl extends ServiceImpl<OaProcessTemplateMapper, ProcessTemplate> implements OaProcessTemplateService {
    @Autowired
    OaProcessTypeService oaProcessTypeService;

    @Override
    public IPage<ProcessTemplate> pageProcessTemplate(Page<ProcessTemplate> pageParam) {

        Page<ProcessTemplate> processTemplatePage = baseMapper.selectPage(pageParam, null);
        List<ProcessTemplate> records = processTemplatePage.getRecords();
        for (ProcessTemplate processTemplate : records) {
            Long processTypeId = processTemplate.getProcessTypeId();
            if(processTypeId==null) {
                continue;
            }
            String ProcessTypeName = oaProcessTypeService.getById(processTypeId).getName();
            processTemplate.setProcessTypeName(ProcessTypeName);

        }

        return processTemplatePage;
    }

    @Override
//    发布（部署流程定义）
    public void publish(Long id) {
        ProcessTemplate processTemplate = baseMapper.selectById(id);
//        status: 1代表已发布， 0代表未发布
        processTemplate.setStatus(1);
        baseMapper.updateById(processTemplate);
//        TODO 发布（部署流程定义）
    }
}
